<template>
    <div>
        <div class="table-area">
            <el-table :data="tableData" style="width: 100%" >
                <el-table-column prop="orderId" label="订单概况" > </el-table-column>
                <el-table-column prop="customer.realName" label="用户信息" > </el-table-column>
                <el-table-column prop="amount" label="订单数量" > </el-table-column>
                <el-table-column prop="status"  label="订单状态"> </el-table-column>
                <!-- <el-table-column prop="address"  label="发货状态"> </el-table-column> -->
                <el-table-column prop="createData"  label="日期"> </el-table-column>
                <el-table-column label="操作" fixed="right" width="100">
                     <template slot-scope="scope" class="opearate-item">
                         <el-row :gutter="20">
                            <el-col :span="12">
                                <el-button @click.native.prevent="sendGoods(scope.$index, tableData)" type="text" size="small"> 发货 </el-button>
                            </el-col>
                            <el-col :span="12">
                                <el-button @click.native.prevent="returnGoods(scope.$index, tableData)" type="text" size="small"> 退货 </el-button>
                            </el-col>
                        </el-row>
                        <el-row :gutter="20">
                            <el-col :span="12">
                                <el-button @click.native.prevent="finishGoods(scope.$index, tableData)" type="text" size="small"> 完成 </el-button>
                            </el-col>
                            <el-col :span="12">
                                <el-button @click.native.prevent="deleteOrder(scope.$index, tableData)" type="text" size="small"> 作废 </el-button>
                            </el-col>
                        </el-row>

                    </template>
                </el-table-column>
            </el-table>
        </div>


        <div class="page-area">
            <el-pagination
                layout="prev, pager, next"
                :total="50">
            </el-pagination>
        </div>
    </div>
</template>
<script>
// 引入LeanCloud存储
var AV = require('leancloud-storage');
// import Order from '@/models/Order.js';
import {getPreMonth} from '@/components/common/util.js'


export default {
    data(){
        return {
            
            activeIndex:'1',  // 活动tab页
            input_text:'', // 搜索内容
            input_start_date:'', // 开始日期
            input_end_date:'', // 结束日期
            tableData: [{ //表格数据
                     orderId:'E20180908174532044900006',
                     goods:[],
                     amount:5,
                     customer:{nickName:'Dovey',realName:'张三',phoneNumber:'18010620509'},
                     createData:'2018-09-08 17:45:32',
                     status:'待发货'
                }, {
                    orderId:'E20180908174532044900006',
                     goods:[],
                     amount:5,
                     customer:{nickName:'Dovey',realName:'李四',phoneNumber:'18010620509'},
                     createData:'2018-09-08 17:45:32',
                     status:'待发货'
                }, {
                   orderId:'E20180908174532044900006',
                     goods:[],
                     amount:5,
                     customer:{nickName:'Dovey',realName:'王五',phoneNumber:'18010620509'},
                     createData:'2018-09-08 17:45:32',
                     status:'待发货'
                }, {
                    orderId:'E20180908174532044900006',
                     goods:[],
                     amount:5,
                     customer:{nickName:'Dovey',realName:'二哈',phoneNumber:'18010620509'},
                     createData:'2018-09-08 17:45:32',
                     status:'待发货'
                }],
                orderData:[
                    {
                        orderId:'E20180908174532044900006',
                        goods:[],
                        amount:5,
                        customer:{nickName:'Dovey',realName:'杨正伟',phoneNumber:'18010620509'},
                        createData:'2018-09-08 17:45:32',
                        status:'待发货'
                    }
                ]
        }
    },
    methods:{
        sendGoods(index,arr){
            this.$message({
                type:'info',
                message:'Send Goods'
            })
        },
        returnGoods(index,arr){
            this.$message({
                type:'info',
                message:'return Goods'
            })
        },
        finishGoods(index,arr){
            this.$message({
                type:'info',
                message:'finish Goods'
            })
        },
        deleteOrder(index,arr){
            this.$message({
                type:'info',
                message:'delete Goods'
            })
        },
        initData(){
            // var　queryStartDate = new AV.Query('Order');      
            // let lastMouth = getPreMonth(new Date().toLocaleDateString())+' 00:00:00';
            // queryStartDate.greaterThanOrEqualTo('createdAt',new Date(lastMouth));
            
            // var queryEndDate = new AV.Query('Order');
            // let now = new Date();
            // now = `${now.getFullYear()}-${now.getMonth()+1}-${now.getDate()} 00:00:00`;
            // queryEndDate.lessThanOrEqualTo('createdAt',new Date(now));

            // var queryStatus = new AV.Query('Order');
            // queryStatus.equalTo('status','SUCCESS');

            // var query = AV.Query.and(queryStartDate,queryStatus);
            
            // // var query =new AV.Query('Order');
            // debugger;
            // query.find().then(records=>{
            //     debugger;
            //     if(records){
            //         console.log(records.toJSON());
            //     }
            // }).catch(error=>{
            //     console.error(error);
            // })
            var cql = "select * from Order where status = 'SUCCESS'";
            AV.Query.doCloudQuery(cql).then(function (data) {
                // results 即为查询结果，它是一个 AV.Object 数组
                var results = data.results;
                console.log(results);
            }, function (error) {
                console.error(error);
            });
            


        }
    },    
    mounted(){
        this.initData();
    }
    
}
</script>

<style scoped>

</style>

